package com.harry.hr.dao.impl;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.harry.hr.dao.ConfigFileDAO;
import com.harry.hr.entity.ConfigFileFirstKind;
import com.harry.hr.entity.ConfigFileSecondKind;
import com.harry.hr.entity.ConfigFileThirdKind;
import com.harry.hr.entity.ConfigMajor;
import com.harry.hr.entity.ConfigMajorKind;
import com.harry.hr.entity.ConfigPrimaryKey;
import com.harry.hr.entity.ConfigPublicChar;
import com.harry.hr.entity.ConfigQuestionFirstKind;
import com.harry.hr.entity.ConfigQuestionSecondKind;
import com.harry.hr.entity.SalaryStandard;

public class ConfigFileDAOImpl extends HibernateDaoSupport implements
		ConfigFileDAO {

	@SuppressWarnings("unchecked")
	public List<ConfigFileFirstKind> getConfigFileFirstKindList() {
		String queryString="from ConfigFileFirstKind";
		return this.getHibernateTemplate().find(queryString);
	}
	
	@SuppressWarnings("unchecked")
	public List<ConfigFileFirstKind> getConfigFileFirstKindList(ConfigFileFirstKind firstKind,MatchMode mode,Order order) {
		DetachedCriteria criteria = DetachedCriteria.forClass(ConfigFileFirstKind.class);
		if(firstKind!=null){
			if(firstKind.getFirstKindId()!=null&&firstKind.getFirstKindId().length()!=0)
				criteria.add(Restrictions.like("firstKindId",firstKind.getFirstKindId(),mode));
			if(firstKind.getFirstKindName()!=null&&firstKind.getFirstKindName().length()!=0)
				criteria.add(Restrictions.like("firstKindName",firstKind.getFirstKindName(),mode));
			if(firstKind.getFirstKindSalaryId()!=null&&firstKind.getFirstKindSalaryId().length()!=0)
				criteria.add(Restrictions.like("firstKindSalaryId",firstKind.getFirstKindSalaryId(),mode));
			if(firstKind.getFirstKindSaleId()!=null&&firstKind.getFirstKindSaleId().length()!=0)
				criteria.add(Restrictions.like("firstKindSaleId",firstKind.getFirstKindSaleId(),mode));
		} 
		criteria.addOrder(order);
		return this.getHibernateTemplate().findByCriteria(criteria);
	}

	@SuppressWarnings("unchecked")
	public List<ConfigFileSecondKind> getConfigFileSecondKindList(String firstKindId) {
		String queryString="from ConfigFileSecondKind secend where secend.firstKindId=?";
		return this.getHibernateTemplate().find(queryString,firstKindId);
	}

	@SuppressWarnings("unchecked")
	public List<ConfigFileThirdKind> getConfigFileThirdKindList(String secondKindId) {
		String queryString="from ConfigFileThirdKind third where third.secondKindId =?";
		return this.getHibernateTemplate().find(queryString,secondKindId);
	}

	@SuppressWarnings("unchecked")
	public List<ConfigMajor> getConfigMajorList(String majorKindId) {
		String queryString="from ConfigMajor c where c.majorKindId=?";
		return this.getHibernateTemplate().find(queryString,majorKindId);
	}

	@SuppressWarnings("unchecked")
	public List<ConfigMajorKind> getConfigMajorKindList() {
		String queryString="from ConfigMajorKind";
		return this.getHibernateTemplate().find(queryString);
	}

	@SuppressWarnings("unchecked")
	public List<ConfigPrimaryKey> getConfigPrimaryKeyList() {
		String queryString="from ConfigPrimaryKey";
		return this.getHibernateTemplate().find(queryString);
	}

	@SuppressWarnings("unchecked")
	public List<ConfigPublicChar> getConfigPublicCharList(ConfigPublicChar publicChar,MatchMode mode,Order order) {
		DetachedCriteria criteria = DetachedCriteria.forClass(ConfigPublicChar.class);
		if(publicChar!=null){
			criteria.add(Restrictions.like("attributeKind",publicChar.getAttributeKind(),mode));
		} 
		criteria.addOrder(order);
		return this.getHibernateTemplate().findByCriteria(criteria);
	}

	@SuppressWarnings("unchecked")
	public List<ConfigQuestionFirstKind> getConfigQuestionFirstKindList() {
		String queryString="from ConfigQuestionFirstKind";
		return this.getHibernateTemplate().find(queryString);
	}

	@SuppressWarnings("unchecked")
	public List<ConfigQuestionSecondKind> getConfigQuestionSecondKindList() {
		String queryString="from ConfigQuestionSecondKind";
		return this.getHibernateTemplate().find(queryString);
	}

	@SuppressWarnings("unchecked")
	public List<SalaryStandard> getSalaryStandardList() {
		String queryString="from SalaryStandard";
		return this.getHibernateTemplate().find(queryString);
	}

	

	
	
}
